
const vm = new Vue({
    el:"#register-main",
    data:{
        admin:{
            username:"",
            password:""
        }
    },
    methods:{
        registerClick:function (){
            var username = vm.admin.username;
            var password = vm.admin.password;
            //var password2 = vm.admin.password2;
            if (escape(username).indexOf("%u") != -1){
                vm.admin.username = "";
                alert("用户名不能含有中文字符");
            }else {
                /*if (password1 != password2){
                    alert("输入密码不匹配，请重新输入");
                    vm.admin.password1 = "";
                    vm.admin.password2 = "";
                }else {

                }*/

                if (username == null && username == ""){
                    alert("账号不能为空");
                }else {
                    if (password != null && password != ""){
                        let index = layer.msg("注册中...",{icon:16});
                        this.$http.post("v1/register/insert",vm.admin,{"emulateJSON":true}).then(function (data){
                            layer.close(index);
                            var status = data.data.status;
                            var resultMsg = data.data.msg;
                            if (status == -1){
                                //注册失败
                                layer.msg(resultMsg);
                            }else {
                                //注册成功
                                layer.msg(resultMsg);
                                var userid = data.data.data.id;
                                self.location='index.html?'+'userid='+userid;
                            }
                        },function (data){
                        });
                    }
                }
            }
        }
    }

});